package Colecciones;

import Modelo.EjecutaConsulta;
import Modelo.Fila;
import java.io.PrintStream;
import java.util.Vector;

public class datosPersonales
{
  public static Fila getDatosPersona(String p_emplid)
  {
    Fila datos = new Fila();
    try
    {
      String consulta = " SELECT FIRST_NAME NOMBRES, LAST_NAME APELLIDOS, SEX GENERO, EMPLID,  BIRTHDATE FECHA_NACIMIENTO,BIRTHPLACE CIUDAD_NACIMIENTO,BIRTHCOUNTRY PAIS_NACIMIENTO , MAR_STATUS ESTADO_CIVIL FROM PS_PERSONAL_DATA  WHERE EMPLID = '" + p_emplid + "'";

      datos = EjecutaConsulta.Ejecutar2(consulta);
    } catch (Exception e) {
      System.out.println("Error: en la consulta de datosPersonales.getDatosPersona " + e.toString());
    }

    return datos;
  }

  public static Fila getDocumentoActual(String p_emplid)
  {
    Fila datos = new Fila();
    try
    {
      String consulta = " SELECT COUNTRY CODIGO_PAIS, NATIONAL_ID_TYPE TIPO_DOCUMENTO ,NATIONAL_ID DOCUMENTO FROM PS_PERS_NID  WHERE PRIMARY_NID='Y'  AND EMPLID= '" + p_emplid + "'";

      datos = EjecutaConsulta.Ejecutar2(consulta);
    } catch (Exception e) {
      System.out.println("Error: en la consulta de datosPersonales.getDocumentoActual " + e.toString());
    }

    return datos;
  }

  public static Fila getEmailPreferido(String p_emplid)
  {
    Fila datos = new Fila();
    try
    {
      String consulta = " SELECT E_ADDR_TYPE TIPO_CORREO, EMAIL_ADDR CORREO  FROM PS_EMAIL_ADDRESSES  WHERE EMPLID= '" + p_emplid + "'" + " AND PREF_EMAIL_FLAG='Y'";

      datos = EjecutaConsulta.Ejecutar2(consulta);
    } catch (Exception e) {
      System.out.println("Error: en la consulta de datosPersonales.getEmailPreferido " + e.toString());
    }

    return datos;
  }

  public static Vector getEmplidByDocumento(String p_documento)
  {
    Vector datos = new Vector();
    try
    {
      String consulta = " SELECT EMPLID FROM PS_PERS_NID  WHERE NATIONAL_ID ='" + p_documento + "'";

      datos = EjecutaConsulta.Ejecutar(consulta);
    } catch (Exception e) {
      System.out.println("Error: en la consulta de datosPersonales.getEmplidByDocumento " + e.toString());
    }

    return datos;
  }

  public static Vector getDirecciones(String p_emplid)
  {
    Vector datos = new Vector();
    try
    {
      String consulta = " SELECT A.ADDRESS_TYPE TIPO_DIRECCION,A.COUNTRY CODIGO_PAIS,A.ADDRESS1,CITY  FROM PS_ADDRESSES A  WHERE A.EMPLID='" + p_emplid + "' " + " AND  A.EFF_STATUS='A' " + " AND  A.EFFDT = (SELECT MAX(B.EFFDT) " + " FROM PS_ADDRESSES B " + " WHERE B.EMPLID=A.EMPLID " + " AND   B.ADDRESS_TYPE = A.ADDRESS_TYPE " + " AND   B.EFFDT <=SYSDATE) ";

      datos = EjecutaConsulta.Ejecutar(consulta);
    } catch (Exception e) {
      System.out.println("Error: en la consulta de datosPersonales.getDirecciones " + e.toString());
    }

    return datos;
  }

  public static Fila getDireccionPermanente(String p_emplid)
  {
    Fila datos = new Fila();
    try
    {
      String consulta = " SELECT A.ADDRESS_TYPE TIPO_DIRECCION,A.COUNTRY CODIGO_PAIS,A.ADDRESS1,CITY  FROM PS_ADDRESSES A  WHERE A.EMPLID='" + p_emplid + "' " + " AND  A.EFF_STATUS='A' " + " AND A.ADDRESS_TYPE ='PERM' " + " AND  A.EFFDT = (SELECT MAX(B.EFFDT) " + " FROM PS_ADDRESSES B " + " WHERE B.EMPLID=A.EMPLID " + " AND   B.ADDRESS_TYPE = A.ADDRESS_TYPE " + " AND   B.EFFDT <=SYSDATE) ";

      datos = EjecutaConsulta.Ejecutar2(consulta);
    } catch (Exception e) {
      System.out.println("Error: en la consulta de datosPersonales.getDireccionPermanente " + e.toString());
    }

    return datos;
  }

  public static Fila getTelefonoFijo(String p_emplid)
  {
    Fila datos = new Fila();
    try
    {
      String consulta = " SELECT PHONE  FROM PS_PERSONAL_PHONE  WHERE EMPLID ='" + p_emplid + "' " + " AND PHONE_TYPE IN ('PERM','HOME')" + " AND ROWNUM=1";

      datos = EjecutaConsulta.Ejecutar2(consulta);
    } catch (Exception e) {
      System.out.println("Error: en la consulta de datosPersonales.getTelefonoFijo " + e.toString());
    }

    return datos;
  }

  public static Fila getCelular(String p_emplid)
  {
    Fila datos = new Fila();
    try
    {
      String consulta = " SELECT PHONE  FROM PS_PERSONAL_PHONE  WHERE EMPLID ='" + p_emplid + "' " + " AND PHONE_TYPE IN ('CELL')";

      datos = EjecutaConsulta.Ejecutar2(consulta);
    } catch (Exception e) {
      System.out.println("Error: en la consulta de datosPersonales.getCelular " + e.toString());
    }

    return datos;
  }

  public static void main(String[] args)
  {
    Modelo.Path.ruta = "..\\WEB-INF\\classes";
    try
    {
      System.out.println(getDatosPersona("0014414"));
      System.out.println(getDirecciones("0014414"));
      System.out.println(getEmailPreferido("0014414"));
      System.out.println(getDocumentoActual("0014414"));
      System.out.println(getEmplidByDocumento("16796985"));
    } catch (Exception e) {
      System.out.println("errro " + e.getMessage());
    }
  }
}